package ButtonInfoFrame;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ButtonInfoFrame extends JFrame {

    private JTextField textField;
    private JButton button1;
    private JButton button2;

    public ButtonInfoFrame() {
        setTitle("Button Info Frame");
        setSize(400, 200);
        setLayout(null);

        // 创建JTextField
        textField = new JTextField();
        textField.setBounds(50, 50, 300, 30);
        add(textField);

        // 创建第一个按钮，并设置其标签和位置
        button1 = new JButton("Button 1");
        button1.setBounds(50, 100, 150, 30);
        add(button1);

        // 创建第二个按钮，并设置其标签和位置
        button2 = new JButton("Button 2");
        button2.setBounds(220, 100, 150, 30);
        add(button2);

        // 为第一个按钮添加ActionListener
        button1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                textField.setText("Button 1 clicked");
            }
        });

        // 为第二个按钮添加ActionListener
        button2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                textField.setText("Button 2 clicked");
            }
        });

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    public static void main(String[] args) {
        new ButtonInfoFrame();
    }
}